< previous page page_539 next page >

Page 539
Creating Data-bound Forms
Once youve created a data environment and Connection and Command objects, youre ready to connect your Command object to a form that can be used for data entry. All you need to do is to add an ADO data control to your project, drag and drop the Command object you created onto a blank form, add the ADO data control to the form, and then write one line of code. I know it sounds too easy, but believe me, it is that easy!
EXERCISE
Binding Command Objects to a Form
1. Add a new form to your project by selecting Project, Add Form from the Visual Basic menu.
2. Add an ADO data control by selecting Project, Components from the Visual Basic menu.
3. Select the Microsoft ADO Data Control 6.0 (OLEDB) option from the list of components.
4. Grab that data control from the toolbox and place it on the new form.
5. Set the Name property of the data control to adcEmp.
6. Set the Caption property to Employees.
7. Position your form within the Visual Basic design environment so that you can see both the form and the Data Environment window.
8. Drag the Command object cmdEmployees onto the form.
9. You should now see the Visual Basic design environment adding labels and text boxes to the form.
10. When this process is complete, you need to set the recordset for the Command object to the Recordset property of the ADO data control.
11. Double-click the form to bring up the Form_Load() event. Write the following line of code in the Load event:
Private Sub Form_Load()
Set adcEmp.Recordset = deEmployees.rscmdEmployees
End Sub
analysis.gifIt is very easy to create a form that displays data. Using the command objects, you can just drag and drop onto a form and write one line of code!

 
< previous page page_539 next page >

If you like this book, buy it!